﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using WeifenLuo.WinFormsUI.Base;

namespace HRM
{
	public struct SelectionParam
	{
		public string	ms_Module;
		public string	[]msa_Conditions;
		public string	ms_SelectionField;
		public string	ms_SelectionName;
		public string	[]msa_ReturnValues;
	}

	/// <summary>
	/// Summary description for Ctrl_Selection.
	/// </summary>
	public class Ctrl_Selection : Ctrl_General
	{
		public Ctrl_Selection()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public DataSet SetData2Selet(string asFormName, string asColName, SelectionParam astrParam)
		{
			try
			{
				switch(asFormName)
				{
                    case "FormPersonalProfile":
						switch(asColName)
						{
                            case "txtIDPosition": return GetPosition();
                            case "txtIDDept": return GetDepartment();
                            case "txtIDResideState": return GetCountry("A");
                            case "txtIDResideCountry": return GetCountry("C");
                            case "txtIDContState": return GetCountry("A");
                            case "txtIDContCountry": return GetCountry("C");
                            case "txtIDNative": return GetCountry("A");
                            case "txtIDNationality": return GetCountry("C");
                            case "txtIDRace": return GetRaceDialect();
                            case "txtIDLiteracy": return GetLiteracy();
                            case "txtIDBank": return GetBank();
                            case "txtIDGLAccGroup": return GetGLAccGrp();
                            case "ID_ContractTypeCont": return GetContractType();
						} break;

                    case "FormCalculatePayroll":
                        switch(asColName)
						{
                            case "txtIDEmp": return GetEmployee();
                            case "txtDept": return GetDepartment();
						} break;

                    case "FormPlaceOfRegistedHI":
                    case "FormHISIPIT_Info":
                    case "FormDependent":
                    case "FormBusinessTrip":
                    case "FormSalaryAdvance":
                    case "FormMaternity":
                    case "FormBonusFee":
                    case "FormAllowanceFee":
                    case "FormOvertimeRegistration":
                    case "FormLeaveRegistration":
                    case "FormManualTimeSheet":
                    case "FormTraining":
                        switch(asColName)
						{
                            case "ID_Emp": return GetEmpWithCheck();
                            case "ID_LeaveType": return GetLeaveType();
                            case "ID_OvertimeType": return GetOTType();
                            case "txtIDEmp": return GetEmployeeWithMaternity();
                            case "txtDept": return GetDepartment();
                            case "ID_Country": return GetCountry(astrParam.msa_Conditions[0]);
                            case "ID_POR_HI": return GetPlaceRegHI();
                            case "ID_POR_Type": return GetPlaceRegHIType();
						} break;

					case "FormBonusType":
					case "FormChildrenCareLeave":
					case "FormCompAllow":
					case "FormCountingNightShiftHours":
					case "FormEarlyOut":
					case "FormLate":
					case "FormMatAtaLeave":
					case "FormNightShiftHours":
					case "FormOT15Appr":
					case "FormOT20Appr":
					case "FormOtherAllowNonTax":
					case "FormOtherAllowToTax":
					case "FormOtherDeductNonTax":
					case "FormOtherDeductToTax":
					case "FormOTPublicDays":
					case "FormSickRiskyAcciLeave":
					case "FormUnpaid":
					case "FormWorkInjWithPay":
						switch(asColName)
						{
							case "Code":
							case "TM_Type": return GetTMType();
						} break;

					default: break;
				}
				return null;
			}
			catch(Exception ex)
			{
				Ctrl_LOG.Print("Selection Controller", "SetData2Selet function", "Error message: '"+ex.Message+"'");
				return null;
			}
		}

        private DataSet GetPosition()
        {
            return GetSelect("Select  ID_Position as [Position ID], Position_Name AS [Position Name]  From HRM_Position", "HRM_Position");
        }	
	
		private DataSet GetDepartment()
		{
            return GetSelect("Select ID_Dept [Dept. ID.], Dept_Name [Dept. Name] From HRM_Department", "HRM_Department");
		}

        private DataSet GetLiteracy()
        {
            return GetSelect("Select ID_Literacy [Literacy ID.], Literacy_Name [Literacy Name] From HRM_Literacy", "HRM_Literacy");
        }

        private DataSet GetGLAccGrp()
        {
            return GetSelect("Select ID_GLAccGroup [GL Account Group ID.], GLAccGroup_Name [GL Account Group Name] From HRM_GLAccGroup_Header", "HRM_GLAccGroup_Header");
        }

        private DataSet GetContractType()
        {
            return GetSelect("Select ID_ContractType [Contract Type ID.], ContractType_Name [Contract Type Name] From HRM_ContractType", "HRM_ContractType");
        }

        private DataSet GetLeaveType()
        {
            return GetSelect("Select ID_LeaveType [Leave Type ID.], LeaveType_Name [Leave Type Name], Percent_Sal [Percent Sal. (%)] From HRM_LeaveType", "HRM_LeaveType");
        }

        private DataSet GetOTType()
        {
            return GetSelect("Select ID_OvertimeType [OT. Type ID.], OvertimeType_Name [OT. Type Name], Percent_Salary [Percent Sal. (%)] From HRM_OvertimeType", "HRM_OvertimeType");
        }

		private DataSet GetPlaceRegHI()
		{
            return GetSelect("Select ID_POR_HI [Place Reg. HI Code], Name_POR [Place Of Registration HI.], Address From HRM_PORHI", "HRM_PORHI");
		}

        private DataSet GetPlaceRegHIType()
        {
            return GetSelect("Select ID_POR_Type [Place Reg. HI Type ID.], NameOfType [Place Of Registration HI. Type Name] From HRM_PORType", "HRM_PORType");
        }

		private DataSet GetCurrency()
		{
			return GetSelect("Select Currency_Code [Loại Tiền], Description [Diễn Giải] From CURRENCY ", "CURRENCY");
		}

		private DataSet GetHealthStatus()
		{
			return GetSelect("Select ID_Health_Status [Mã Tình Trạng Sức Khoẻ] , Description  [Tình Trạng Sức Khoẻ] From Health_Status ", "Health_Status");
		}

		private DataSet GetEmployee()
		{
            return GetSelect("Select ID_Emp [Employee ID.], Emp_NameVN [Full Name]  From HRM_PersonalProfile", "HRM_PersonalProfile");
		}

        private DataSet GetEmployeeWithMaternity()
        {
            return GetSelect("Select ID_Emp [Employee ID.], Emp_NameVN [Full Name]  From HRM_PersonalProfile WHere Gender = 1", "HRM_PersonalProfile");
        }

        private DataSet GetEmpWithCheck()
        {
            return GetSelect("Select CAST( B.Checked AS bit) AS [Selection], ID_Emp [Employee ID.], Emp_NameVN [Full Name]  From HRM_PersonalProfile, (select 0 Checked) B ", "HRM_PersonalProfile");
        }
        
		private DataSet GetResignation()
		{
			return GetSelect( "Select ID_Resignation AS [Mã Nghỉ Việc], [Description] AS [Lý Do Nghỉ Việc] From Resignation_Reason  ", "Resignation_Reason" );
		}

		private DataSet GetTimeType()
		{
			return GetSelect( "Select Type_Code AS [Mã Giờ Công], [Description] [Tên Giờ Công] From TM_TYPE ", "TM_TYPE" );
		}

		private DataSet GetCountry(string as_CType)
		{
            return GetSelect("Select ID_Country AS [Country ID.], Name_Country AS [Country Name] From HRM_Country Where CType = '" + as_CType + "' ", "HRM_Country");
		}

		private DataSet GetBank()
		{
            return GetSelect("Select ID_Bank AS [Bank Code], Bank_Name AS [Bank Name] From HRM_Bank", "HRM_Bank");
		}

		private DataSet GetRaceDialect()
		{
            return GetSelect("Select ID_Race AS [Race/Dialect ID.], Race_Name AS [Race/Dialect Name] From HRM_Race", "HRM_Race");
		}

		private DataSet GetTMType()
		{
			return GetSelect( "Select  TM_Type [TM. Type], Time_Type [Time Type] From TM_TYPE ", "TM_TYPE" );
		}

	}
}